#set($layout = "blank.html")
<link rel="stylesheet" href="$!{base}/resources/assets/css/chosen.css" />
<div class="space-4"></div>
<div class="row">
	<div class="col-xs-1"></div>
	<div class="col-xs-10">
		<form id="addContractForm">
			<div>
				<label> 项目部 <small class="text-info">合同所属项目部</small></label>
				<div>
					<select class="chosen-select form-control" name="projectId" id="projectId" data-placeholder="请选择项目部">
						<option value="0">请选择项目部</option> #foreach($project in $obj.data.projects)
						<!-- 全部用户 -->
						<option value="$!{project.id}" #if($project.id == $!obj.data.contract.p_id)selected #end>$project.name $!project.code</option>
						<!-- 遍历结束 --> #end
					</select>
				</div>
			</div>
			
			<div>
				<label> 合同名称 <small class="text-info">合同名称</small></label>
				<div>
					<input class="form-control" type="text" placeholder="请输入合同名称" name="name" value="$!obj.data.contract.c_name" data-type='required' data-error='请输入合同名称'>
				</div>
			</div>

			<div>
				<label> 合同编码 <small class="text-info">合同编码</small></label>
				<div>
					<input class="form-control" type="text" placeholder="请输入合同编码" name="code" value="$!obj.data.contract.c_code" data-type='required' data-error='请输入合同编码'>
				</div>
			</div>

			<div>
				<label> 合同负责人 <small class="text-info">合同负责人</small></label>
				<div>
					<select class="chosen-select form-control" name="principalId" id="principalId" data-placeholder="请选择合同负责人">
						<option value="0">请选择选合同负责人</option> #foreach($user in $obj.data.users)
						<!-- 全部用户 -->
						<option value="$!{user.id}" #if($user.id== $!obj.data.contract.u_id )selected #end>$user.realName $!user.name</option>
						<!-- 遍历结束 --> #end
					</select>
				</div>
			</div>

			<div>
				<label> 合同介绍 <small class="text-info">合同介绍信息</small></label>
				<div>
					<textarea class="form-control limited autosize-transition" name="description" maxlength="500" placeholder="请输入合同描述信息">$!obj.data.contract.c_des</textarea>
				</div>
			</div>

			<div class="space-4"></div>
			<div class="space-4"></div>
			<input type="hidden" name="id" id="contractId" value="$!obj.data.contract.id">
			<div class="pull-right" style="margin-right:45px">
				<button type="button" class="btn btn-sm btn-primary" onclick="save()">
					<i class="fa fa-save"></i> 提交
				</button>
				<button class="btn btn-sm btn-warning btn-dialog-undo">
					<i class="fa fa-undo"></i> 返回
				</button>
			</div>
		</form>
	</div>
	<div class="col-xs-1"></div>
</div>
<script src="$!{base}/resources/assets/js/jquery.inputlimiter.1.3.1.js"></script>
<script src="$!{base}/resources/assets/js/jquery.autosize.js"></script>
<script src="$!{base}/resources/assets/js/chosen.jquery.js"></script>
<script>
	$(function() {
		//描述框效果
		$('textarea.limited').inputlimiter({
			remText : '还可以输入 %n 字',
			limitText : '最大允许: %n 字.'
		});
		$('textarea[class*=autosize]').autosize({
			append : "\n"
		});

		//chosen
		$('.chosen-select').chosen();
	})

	function save() {
		if ($('input').validation()) {
			if ($("#projectId").val() == 0) {
				validationFail("请选择项目部", $("#projectId").parent());
				return;
			}
			if ($("#principalId").val() == 0) {
				validationFail("请选择合同负责人", $("#principalId").parent());
				return;
			}
			if ($('#contractId').val()) {
				$.post(getRootPath() + '/contract/edit', $('#addContractForm').serialize(), commonAjaxCallBasck, 'json');
			} else {
				$.post(getRootPath() + '/contract/add', $('#addContractForm').serialize(), commonAjaxCallBasck, 'json');
			}

		}
	}
</script>